package com.leyou.search.listeners;


import com.leyou.search.service.IndexService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class Listener {

    //声明路由key  当saleable为true时上架，false时下架
    //String routingKey = saleable ? "item.up" : "item.down";
    //向指定的交换机发送请求，消息内容为spuId
    //this.amqpTemplate.convertAndSend("leyou.item",routingKey,supId);

    @Autowired
    private IndexService indexService;


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name ="item.queue" , durable = "true"),
            exchange = @Exchange(name = "leyou.item", type = ExchangeTypes.TOPIC),
            key = "item.up"))
    public void itemUp(Long supId) {

        indexService.itemUp(supId);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name ="item.queue" , durable = "true"),
            exchange = @Exchange(name = "leyou.item", type = ExchangeTypes.TOPIC),
            key = "item.down"))
    public void itemDown(Long supId) {

        indexService.itemDown(supId);
    }


}
